package com.lwc.backendsinglestructure.strategy.loginStrategy;

import com.lwc.backendsinglestructure.domain.dto.user.LoginForm;
import com.lwc.backendsinglestructure.domain.entity.User;
import com.lwc.backendsinglestructure.exception.BusinessException;
import com.lwc.backendsinglestructure.exception.ErrorCode;
import com.lwc.backendsinglestructure.mapper.UserMapper;
import com.lwc.backendsinglestructure.strategy.LoginHandler;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 微信登录
 */
@Component("wx_Login")
public class WxLoginHandler  implements LoginHandler {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(LoginForm loginRequest) {
        String openId = loginRequest.getOpenId();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("open_id", openId);
        User user = userMapper.selectOneByQuery(queryWrapper);
        if(user != null){
            return user;
        }
        return null;
    }
}
